package ${basePackage}.${controllerPackage};

import com.feng.cloud.common.response.RestResponse;
import com.feng.cloud.common.response.TableResultResponse;
import ${basePackage}.${entityPackage}.${className};
import ${basePackage}.${servicePackage}.I${className}Service;
import lombok.extern.slf4j.Slf4j;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * ${tableComment} Controller
 *
 * @author ${author}
 * @date ${date}
 */
@Slf4j
@Validated
@RestController
@AllArgsConstructor
public class ${className}Controller implements I${className}Controller {

    private final ${className}Service ${className?uncap_first}Service;

    @Override
    @PreAuthorize("hasAuthority('${className?uncap_first}:list')")
    public RestResponse<List<${className}>> find${className}s(${className} ${className?uncap_first}) {
        return new RestResponse<List<${className}>>().data(this.${className?uncap_first}Service.find${className}s(${className?uncap_first}));
    }

    @Override
    @PreAuthorize("hasAuthority('${className?uncap_first}:list')")
    public RestResponse<${className}> findOne${className}(@PathVariable Long id) {
        return new RestResponse<${className}>.data(this.${className?uncap_first}Service.getById(id));
    }

    @Override
    @PreAuthorize("hasAuthority('${className?uncap_first}:add')")
    public RestResponse<${className}> add${className}(@Valid ${className} ${className?uncap_first}) {
        this.${className?uncap_first}Service.create(${className?uncap_first});
        return new RestResponse<${className}>.data(${className?uncap_first});
    }

    @Override
    @PreAuthorize("hasAuthority('${className?uncap_first}:update')")
    public RestResponse<${className}> update(@Valid ${className} ${className?uncap_first}) {
        this.${className?uncap_first}Service.update(${className?uncap_first});
        return new RestResponse<${className}>().data(${className?uncap_first});
    }
}